Repository navigation
Conversation
resolveBearerActor and the MCP tests' contextForOrganizer each turned an organizer's session into the tool context by hand, and the route copied the fields over once more. They now share bearerOrganizer in the bearer seam, ToolContext is its type plus db, and the route spreads it, so a field added to the bearer path can't be missed by the tests and evals. Fixes #1141. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_016YZ9SSbFFg2F4VY28wUau4
Tophat: passedSee it: https://claude.ai/artifact/7Wf3Ne1VPv5k821mqtju7T
Worth a look: the route now spreads the whole resolution, minus Not checked on the base: the viewer and deleted-organizer cases. I ran them on the head only, and their wording comes from code this PR doesn't touch. Ran 09a688e against a820439 locally, MCP over HTTP with a token from the real OAuth flow, made-up data. https://claude.ai/code/session_016YZ9STFWdWM98i7mGfTd2w Generated by Claude Code |
richshaw
left a comment
There was a problem hiding this comment.
Review: passed (round 1)
bearerOrganizer is now the only place a session becomes a tool context. resolveBearerActor, contextForOrganizer and the route all go through it, and they build the same fields as before, including the 401 for an organizer who is gone. Nothing in src still uses ToolWorkspace or bearerWorkspaces. Both "Done when" items are met, and so is the issue's outline.
Blocking (0)
Optional (3):
route.ts:109: the context now takes everything exceptokandauthInfo, so any field added later to the resolution reaches every tool. The tophat flagged this too. Returning{ ok, organizer, authInfo }would make adding a field a deliberate choice.bearer.ts:24: the file's seam comment now sits on the exportedBearerOrganizer, so it shows as that type's hover doc. Moving it ontoresolveBearerActorwould fix that.context.ts:1: the type-onlyBearerOrganizerimport is what the issue planned. CLAUDE.md's "only auth import" line could name it.
Earlier threads: none
Checks: CI is green on 09a688e (lint-type-test, e2e, CodeQL). The tophat passed on this SHA. I ran code-review at high effort.
This waits for you because it touches src/auth/bearer.ts and the MCP route, which are high-risk. It changes no behaviour. Card: https://claude.ai/artifact/7Wf3Ne1VPv5k821mqtju7T
https://claude.ai/code/session_016YZ9SVJHryH4EUPxis53cd
Generated by Claude Code
richshaw
left a comment
There was a problem hiding this comment.
Sending this back for one change, in the thread on route.ts. Everything else looks right: an independent security review found authorization unchanged (actor, scopes, workspaces, roles and the 401 for a missing organizer) and nothing sensitive reaching tools today.
Optional, if it's quick while you're in there: move the file's seam comment off BearerOrganizer back onto resolveBearerActor (it now shows as the type's hover doc), and add a line to BearerOrganizer's doc comment saying every field on it reaches every tool, so never put token material there.
https://claude.ai/code/session_016YZ9SVfNPHkNsZgUBaTPSS
Generated by Claude Code
resolveBearerActor now returns { ok, organizer, authInfo }, and the route
builds the tool context from auth.organizer alone, so a field reaches
tools only once it is added to BearerOrganizer. The route test checks the
context has exactly the expected keys and no auth info, even when the
resolution carries something extra. The seam comment moves back onto
resolveBearerActor, and BearerOrganizer's says that every field reaches
every tool.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016YZ9SVvPGrXSNjSDiwe5Ch
Tophat: passedSee it: https://claude.ai/artifact/7Wf3Ne1VPv5k821mqtju7T
This time the viewer and deleted-organizer cases also ran on the base, which the first tophat didn't do. Ran 154b298 against a820439 locally, MCP over HTTP with tokens from the real OAuth flow, made-up data. https://claude.ai/code/session_016YZ9SW6QmGhHSwuvQcJpBm Generated by Claude Code |
Fixes #1141.
Session: https://claude.ai/code/session_016YZ9SSbFFg2F4VY28wUau4
The problem
The code that turns a signed-in organizer into the context an MCP tool runs with was written out three times.
resolveBearerActorbuilt it in production,contextForOrganizer(used by the MCP DB tests and the follow-up evals) rebuilt it field by field, and the route copied the six fields intoToolContextone at a time.BearerWorkspaceandToolWorkspacewere the same type. If a field was added to the bearer path but missed in the test copy, the MCP tests would keep running on a context production no longer builds.The fix
src/auth/bearer.ts: a new exportedBearerOrganizertype (actor, scopes, clientId, defaultWorkspaceId, workspaces, locale) and a purebearerOrganizer(session, clientId, scopes). It callstoActor, narrows the kind, copies the actor withvia(the comment about not mutating the React-cached actor moved with it), and maps the memberships. It replacesbearerWorkspaces.BearerResolution's ok branch is{ ok: true; organizer: BearerOrganizer; authInfo }, so the organizer and the SDK's auth info, which carries the raw token, stay apart.BearerOrganizer's doc comment says that every field on it reaches every tool. The seam comment sits onresolveBearerActor.src/mcp/context.ts:ToolContextisBearerOrganizer & { db }.ToolWorkspaceis gone. The only new import is a type-onlyBearerOrganizerfrom the seam module, and tool handlers still import nothing from@/auth.src/mcp/testing/context.ts: loads the session, callsbearerOrganizer, and throws if it gives null.{ db: getDb(), ...auth.organizer }and handsauth.authInfoto the SDK on its own, so a field reaches tools only once it's added toBearerOrganizer(owner's review).No behaviour changes, so there's no CHANGELOG entry. It touches
src/auth/and the MCP route, so it waits for the owner. #1135 (from a fork) changes key-error logging inbearer.ts. The lines don't overlap, but whichever lands second needs a small merge.Tests
route.test.tschecks that the context the tools receive has exactly the expected keys, with noauthInfoand no copy of the token, even when the resolution carries an extra field. With the old spread in the route, it fails.tools.db.test.tsand the OAuth flow DB tests run throughcontextForOrganizerandresolveBearerActor.grep -rn "ToolWorkspace\|bearerWorkspaces" srcfinds nothing.pnpm lint && pnpm format:check && pnpm typecheck && pnpm knip && pnpm testpass (3895 tests).pnpm test:dbpasses.🤖 Generated with Claude Code
https://claude.ai/code/session_016YZ9SVvPGrXSNjSDiwe5Ch